import collections
class Solution(object):
    def countLargestGroup(self, n):
        d = collections.defaultdict(int)
        for i in range(1, n + 1):
            t = 0
            for c in str(i):
                t += int(c)
            d[t] += 1
        m = max(d.values())
        ans = 0
        for key in d:
            if d[key] == m:
                ans += 1
        return ans